package com.demo.server.util;

import java.util.Date;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;

public class UUIDUtil {

	private static final AtomicInteger counter = new AtomicInteger(0);

	public static int getNextSequence() {
		return counter.getAndIncrement();
	}

	public static String getUUID() {
		return UUID.randomUUID().toString();
	}

	public static String get32UUID() {
		return UUID.randomUUID().toString().trim().replaceAll("-", "");
	}
	
	public static String getSnow() {
		return IdUtil.getSnowflakeNextIdStr();
	}
	
	public static String getUniqStr() {
		long time = System.currentTimeMillis() -1704038400000l;  //1704038400000l  是 20240101000000.000 时间戳
		return Long.toHexString(time) + RandomUtil.randomString(4);
	}
	
	

	public static String getTimeRandom(int bound) {
		int random = new Random().nextInt(bound);
		String format = "%0" + String.valueOf(bound - 1).length() + "d";
		String randomStr = String.format(format, random);
		System.out.println(randomStr);
		String time = String.valueOf(System.currentTimeMillis());
		return time + randomStr;
	}
	
	public static String getDateRandom(int bound) {
		String dataStr = DateUtil.format(new Date(), "yyyyMMdd");
		int random = new Random().nextInt(bound);
		String format = "%0" + String.valueOf(bound - 1).length() + "d";
		String randomStr = String.format(format, random);
		System.out.println(randomStr);
		return dataStr + randomStr;
	}

	public static void main(String[] args) {
		System.out.println(getDateRandom(10000));
		System.out.println(getTimeRandom(4));
	}

}